package edu.ustb.Controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import edu.ustb.domain.Goods;
import edu.ustb.service.GoodsService;
import edu.ustb.service.GoodsServiceImpl;

@SuppressWarnings("serial")
@WebServlet("/admin/goods/search.action")
public class GoodsSearchController extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String goodsname = request.getParameter("goodsName");
		String minprice = request.getParameter("minPrice");
		String maxprice = request.getParameter("maxPrice");
		String pageNum = request.getParameter("page");
		
		GoodsService goodsSearchService= new GoodsServiceImpl();
	    
		if(pageNum==null)
		{
			pageNum="1";
		}
		PageHelper.startPage(Integer.parseInt(pageNum), 5);
		List<Goods>goodslist=goodsSearchService.showAll(goodsname,minprice,maxprice);
		
		PageInfo<Goods> pageInfo = new PageInfo<>(goodslist);
		request.setAttribute("pageInfo", pageInfo);
		request.setAttribute("goodsList", goodslist);
		request.getRequestDispatcher("/admin/goods/show.jsp").forward(request, response);
	}

}
